package com.smedi.ismedi.inmail.core.domain.aggregatemodel.announcement;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.Organization;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.Person;
import lombok.*;

import java.time.LocalDateTime;

/**
 * 接收人
 *
 * @author 姜钦轩
 * @date 2021/08/29
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class Receiver extends Person {
    /**
     * 是否已读 默认未读
     */
    private Boolean isRead;

    /**
     * 查看时间
     */
    private LocalDateTime readTime;

    /**
     * 人员排序
     */
    private Integer personOrder;

    public Receiver(Long id, String name, Boolean internal, Boolean isRead, LocalDateTime readTime, Organization organization) {
        super();
        this.id = id;
        this.name = name;
        this.internal = internal;
        this.isRead = isRead;
        this.readTime = readTime;
        this.organization = organization;
    }

    public static Receiver.ReceiverBuilder builder() {
        return new ReceiverBuilder();
    }

    public static class ReceiverBuilder {
        private Long id;
        private String name;
        private Boolean internal;
        private Boolean isRead;
        private LocalDateTime readTime;
        private Organization organization;

        ReceiverBuilder() {
        }

        public Receiver.ReceiverBuilder id(final Long id) {
            this.id = id;
            return this;
        }

        public Receiver.ReceiverBuilder name(final String name) {
            this.name = name;
            return this;
        }

        public Receiver.ReceiverBuilder internal(final Boolean internal) {
            this.internal = internal;
            return this;
        }

        public Receiver.ReceiverBuilder isRead(final Boolean isRead) {
            this.isRead = isRead;
            return this;
        }

        public Receiver.ReceiverBuilder readTime(final LocalDateTime readTime) {
            this.readTime = readTime;
            return this;
        }

        public Receiver.ReceiverBuilder organization(final Organization organization) {
            this.organization = organization;
            return this;
        }

        public Receiver build() {
            return new Receiver(this.id, this.name, this.internal, this.isRead, this.readTime, this.organization);
        }
    }

    public Boolean getIsRead() {
        return ObjectUtils.isNotNull(this.readTime);
    }
}
